package com.bezdelnick.forum.web.component;

import com.bezdelnick.forum.domain.AppUser;
import com.bezdelnick.forum.web.page.SuperAdminPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: Bezdelnick
 * Date: 24.08.12
 * Time: 17:51
 * To change this template use File | Settings | File Templates.
 */
public class ModeratorsList extends ListView {
    private static final Logger LOGGER = LoggerFactory.getLogger(ModeratorsList.class);

    public ModeratorsList(String id, List list) {
        super(id, list);
    }

    @Override
    protected void populateItem(ListItem listItem) {
        try {
            AppUser appUser = (AppUser) listItem.getModelObject();

            Label lblUsername = new Label("username", appUser.getUsername());
            listItem.add(lblUsername);

            Label lblEmail = new Label("email", appUser.getEmail());
            listItem.add(lblEmail);

            BookmarkablePageLink bplActionActivation = new BookmarkablePageLink("action_1", SuperAdminPage.class);
            bplActionActivation.getPageParameters().add("action", "activation");
            bplActionActivation.getPageParameters().add("id", appUser.getId());
            listItem.add(bplActionActivation);

            BookmarkablePageLink bplActionRemove = new BookmarkablePageLink("action_2", SuperAdminPage.class);
            bplActionRemove.getPageParameters().add("action", "remove");
            bplActionRemove.getPageParameters().add("id", appUser.getId());
            listItem.add(bplActionRemove);

        } catch (Exception ex) {
            LOGGER.error(ex.getMessage());
        }
    }
}
